home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / misc / IOBlixDevKitR2.lha / IOBlixDevKit / C / examples / QueryUARTs.c < prev   
C/C++ Source or Header  |  1999-01-03  |  3KB  |  75 lines

  1. /*
  2.     This program is meant to demonstrate how to get all necessary information
  3.     about a specific chip on an IOBlix board and how to program that chip in a
  4.     system-friendly manner
  5. */
  6.  
  7. #include <exec/exec.h>
  8. #include <resources/ioblix.h>
  9. #include <ioblix/uart.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/ioblix.h>
  15.  
  16.  
  17. UBYTE __aligned myname[]="QueryUARTs 37.1 "__AMIGADATE__;
  18. UBYTE __aligned version[]="$VER: QueryUARTs 37.1 "__AMIGADATE__;
  19. UBYTE __aligned copyright[]="(C)opyright 1998,1999 by Thore Böckelmann and RBM Computertechnik. All rights reserved";
  20.  
  21. struct IOBlixResource *IOBlixBase = NULL;
  22.  
  23. void main(void)
  24. {
  25.     struct IOBlixChipNode *chipNode;
  26.     ULONG board;
  27.     ULONG unit;
  28.     UBYTE *prevOwner;
  29.     struct UART *uart;
  30.  
  31.     IOBlixBase = (struct IOBlixResource *)OpenResource(IOBLIXRESNAME);
  32.     if (IOBlixBase) {
  33.         for (board = 0; board < IOBLIX_MAX_Z2_BOARDS; board++) {
  34.             for (unit = 0; unit < IOBLIX_Z2_NUM_SERUNITS; unit++) {
  35.                 /* first simply try to find each serial UART      */
  36.                 /* if it is available then print some information */
  37.                 chipNode = FindChip(ICT_SERIAL_Z2_CHIP, board*10+unit);
  38.                 if (chipNode) {
  39.                     printf("UART %ld on board %ld is a \"%s\" with %ld bytes FIFO\n", unit, board, chipNode->icn_Description, chipNode->icns_FIFOSize);
  40.                     printf("current user: %s\n", (chipNode->icn_Owner) ? chipNode->icn_Owner : (UBYTE *)"nobody");
  41.  
  42.                     /* now try to obtain chip for exclusive use */
  43.                     prevOwner = NULL;
  44.                     chipNode = ObtainChip(ICT_SERIAL_Z2_CHIP, board*10+unit, myname, &prevOwner);
  45.                     if (chipNode) {
  46.                         if (chipNode->icns_UARTType == SCPT_16654) {
  47.                             uart = (struct UART *)chipNode->icn_Address;
  48.                             /* now play a bit with the UART's scratch register */
  49.                             /* every value written to this register should also be read back */
  50.                             /* else something really bad has happened */
  51.                             uart->scr = 0x55;
  52.                             if (uart->scr != 0x55) printf("read failure\n");
  53.                             uart->scr = 0xaa;
  54.                             if (uart->scr != 0xaa) printf("read failure\n");
  55.                         } else {
  56.                             printf("UART is not a 16C654!\n");
  57.                         }
  58.  
  59.                         /* now release the chip again */
  60.                         ReleaseChip(chipNode);
  61.                     } else {
  62.                         /* ObtainChip() failed, so let's check for other owners */
  63.                         if (prevOwner) printf("chip is already in use by \"%s\"\n", prevOwner);
  64.                     }
  65.                 } else {
  66.                     printf("UART %ld on board %ld is not available\n", unit, board);
  67.                 }
  68.             }
  69.         }
  70.     } else {
  71.         printf("Can't find ioblix.resource. Please run SetupIOBlix\n");
  72.     }
  73. }
  74.  
  75.